package com.obradovicnjegovan.webprodavnica.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;

public interface HibernateDao {

	Session getSession();
	void setSession(Session session);

	/**
	 * Gets all objects which type is <code>searchForType</code>. If there are
	 * not any object of that type, returns empty list. Supertypes may be used.
	 * If <code>Object.class</code> was provided as a search parameter, the
	 * resulting list will contain all managed objects.
	 * 
	 * @param searchForType type of object that will be searched for
	 * @return a list of all objects that are of certain type. The list is empty if there are not any object of that type
	 */
	<T> List<T> get(Class<T> searchForType);

	/**
	 * Gets the concrete object that has the provided id and a concrete type. 
	 * If such object does not exist, returns null. 
	 * 
	 * @param searchForType type of object that will be searched for
	 * @param id id of object
	 * @return concrete object of a given type and id. <code>null</code> if such
	 * object does not exist.
	 */
	<T> T get(Serializable id, Class<T> searchForType);
	
	/**
	 * Gets all objects...
	 * 
	 * @param searchForType
	 * @param propertyName
	 * @return  a list of all objects ...
	 */
	<T> List<T> getDescOrder(Class<T> searchForType, String propertyName, int maxValue);

	/**
	 * Persists the object.
	 * @param object the object that is going to be persisted
	 */
	void save(Object object);

	/**
	 * Removes the object from the persistance mechanism.
	 * @param object the object that is going to be deleted
	 */
	void delete(Object object);

	/**
	 * Deletes all objects of certain type from the persistent storage
	 * mechanism. To delete all possible objects,
	 * pass <code>java.lang.Object</code> as the parameter.
	 * @param clazz the type of objects that are going to be deleted.
	 */
	@SuppressWarnings("rawtypes")
	void deleteAll(Class clazz);

	/**
	 * Performs writing to the storage mechanism explicitly. Transparent storage
	 * mechanism should decide when to do the writing. due to the performance 
	 * reasons, usually at the end of the successful transaction.
	 * Thus, this method should not be called explicitly unless we want to 
	 * utilize the constraint checking provided by the storage mechanism at
	 * some point inside a transaction.
	 */
	void flush();

}
